@extends('layout.main')

@section('content')
    <div class="col-sm-8 blog-main">
        <div class="blog-post">
            <div style="display:inline-flex">
                <h2 class="blog-post-title"> {{ $post->title }} </h2>
                @can('update', $post)
                <span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
                <a style="margin: auto"  href="/posts/edit/{{ $post->id }}">
                    <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
                </a>
                @endcan
                @can('delete', $post)
                <span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
                <a style="margin: auto"  href="/posts/delete/{{ $post->id }}">
                    <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
                </a>
                @endcan
            </div>

            <p class="blog-post-meta">{{ $post->created_at->format('Y-m-d H:i:s') ?? '' }} &nbsp; by &nbsp; <a href="/user/{{ $post->user->id }}">{{ $post->user->name }}</a></p>

            <div> {!! $post->content !!} </div>
            <br>
            <div>
                @if($post->zan(\Auth::id())->exists())
                    <button type="button" onclick="location.href=this.dataset.url" data-url="/posts/unzan/{{ $post->id }}" class="btn btn-default btn-sm">
                        <span  class="glyphicon glyphicon-thumbs-down"></span> 取消
                    </button>
                @else
                    <button type="button" onclick="location.href=this.dataset.url" data-url="/posts/zan/{{ $post->id }}" class="btn btn-info btn-sm">
                        <span class="glyphicon glyphicon-thumbs-up"></span> 赞
                    </button>
                @endif
            </div>
        </div>

        <div class="panel panel-default">
            <!-- Default panel contents -->
            <div class="panel-heading">发表评论</div>

            <!-- List group -->
            <ul class="list-group">
                <form action="/posts/comments/{{ $post->id }}" method="post">
                    {{ csrf_field() }}
                    <li class="list-group-item">
                        <textarea name="content" class="form-control" rows="4"></textarea>
                        @include('layout.error')
                        <button class="btn btn-default" type="submit">提交</button>
                    </li>
                </form>

            </ul>
        </div>

        <div class="panel panel-default">
            <!-- Default panel contents -->
            <div class="panel-heading">最新评论</div>

            <!-- List group -->
            <ul class="list-group">
                @foreach($post->comments as $comment)
                <li class="list-group-item">
                    <h5>{{ $comment->created_at }} by {{ $comment->user->name }}</h5>
                    <div>
                        {{ $comment->content }}
                    </div>
                </li>
                @endforeach
            </ul>
        </div>
    </div><!-- /.blog-main -->
@endsection